﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Registered_Student_Management
{
    public partial class F_NewHR : Form
    {
        string connection_string = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=Database.mdb;Jet OLEDB:Database Password=51002201";
        public F_NewHR()
        {
            InitializeComponent();
        }

        private void F_NewHR_Load(object sender, EventArgs e)
        {
            try
            {
                GB_NewHR.Visible = true;
                // load data to combobox sobuoihoc
                string[] s = { "nam", "nữ" };

                this.CbB_gioitinhHR.DataSource = s;

                string[] x = { "giảng viên", "nhân viên" };

                this.CbB_chucvuHR.DataSource = x;

            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }

        private void BT_AddHR_Click(object sender, EventArgs e)
        {
            try
            {
                if (TB_tenHR.Text == "" || DTP_ngaysinhHR.Text == "" || CbB_gioitinhHR.Text == "" || CbB_chucvuHR.Text == "" || TB_diachiHR.Text == "" || TB_sdtHR.Text == "" || TB_emailHR.Text == "")
                {
                    MessageBox.Show("Nhập Đầy Đủ Thông Tin", "Yêu Cầu");
                }

                else
                {
                    OleDbConnection cnInsert = new OleDbConnection();
                    cnInsert.ConnectionString = connection_string;
                    cnInsert.Open();
                    OleDbCommand commandInsertNewHR = new OleDbCommand();
                    commandInsertNewHR.Connection = cnInsert;

                  
                    string name_position = CbB_chucvuHR.Text;
                    string fullname = TB_tenHR.Text, gender = CbB_gioitinhHR.Text, phone = TB_sdtHR.Text, email = TB_emailHR.Text, address = TB_diachiHR.Text;
                    string birthday = DTP_ngaysinhHR.Value.ToShortDateString();
                    
                    //insert new HR to database


                    commandInsertNewHR.CommandText = "insert into teacher (fullname, gender,phone,email,address, birthday, [name_position]) values('" + fullname + "','" + gender + "', '" + phone + "','" + email + "','" + address + "','" + birthday + "','" + name_position + "')";
                    commandInsertNewHR.ExecuteNonQuery();

                    cnInsert.Close();
                    cnInsert.Dispose();
                    cnInsert = null;

                    MessageBox.Show("Thêm Nhân Sự Thành Công", "Thông Báo");
                    Close();
                    
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
    }
}
